package top.lidee.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //允许访问的路径
        registry.addMapping("/**")
                //配置请求来源
            .allowedOriginPatterns("*")
                //是否允许携带参数
            .allowCredentials(true)
                //允许跨域的方法
            .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                //最大响应时间
            .maxAge(3600)
            .allowedHeaders("*");

    }
}
